#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>

int main()
{
    int sockfd;
    struct sockaddr_in servaddr;

    sockfd = socket(PF_INET, SOCK_DGRAM, 0);

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port = htons(50001);

    bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
	
	char buff[1024];
	struct sockaddr_in addr;
	socklen_t addr_len = sizeof(addr);
	recvfrom(sockfd, buff, sizeof(buff), 0,(struct sockaddr*)&addr,(socklen_t*)&addr_len);
	printf("recv: %s",buff);
	
	sendto(sockfd,buff,strlen(buff),0,(struct sockaddr*)&addr,addr_len);
	printf("send: %s",buff);

    close(sockfd);
}